﻿namespace SERFLITEMAX20.Viewer
{
    using System;
    using System.Collections;
    using System.Drawing;
    using System.Xml.Serialization;

    [XmlRoot("Settings", Namespace="", IsNullable=false)]
    public class clsSettings
    {
        [XmlArray("DisplayItems"), XmlArrayItem("DisplayItem", typeof(clsDisplayItem))]
        public ArrayList arrDisplayItems = new ArrayList();
        [XmlIgnore]
        public Hashtable DisplayItems = new Hashtable();
        [XmlAttribute("Filter")]
        public bool Filter = false;
        [XmlAttribute("FormHeight")]
        public int FormHeight = 300;
        [XmlAttribute("FormWidth")]
        public int FormWidth = 300;
        [XmlAttribute("FormX")]
        public int FormX = 0;
        [XmlAttribute("FormY")]
        public int FormY = 0;
        [XmlAttribute("MinimapRadius")]
        public int MinimapRadius = 1;
        [XmlAttribute("Port")]
        public string Port = "10000";
        [XmlAttribute("RotateMap")]
        public bool RotateMap = false;
        [XmlAttribute("Server")]
        public string Server = "192.168.33.197";
        [XmlAttribute("ShowMinimap")]
        public bool ShowMinimap = true;
        [XmlAttribute("StayOnTop")]
        public bool StayOnTop = true;

        public clsDisplayItem GetDisplayItem(string id, clsDisplayItem oldDI)
        {
            clsDisplayItem item = (clsDisplayItem) this.DisplayItems[id];
            if (item != null)
            {
                return item;
            }
            return oldDI;
        }

        public void LoadDefaults()
        {
            this.arrDisplayItems.Clear();
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Metal Ore]", Color.White.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Weed]", Color.White.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Fish]", Color.White.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Treasure]", Color.Yellow.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Other]", Color.DarkTurquoise.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Dynamic]", Color.YellowGreen.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[NPC's: Agressive]", Color.Red.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[NPC's: Neutral]", Color.Yellow.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[NPC's: Friendly]", Color.Green.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[NPC's: Dead]", Color.Gray.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.BothNameAndLevel, "[Players: Agressive]", Color.DarkRed.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Players: Neutral]", Color.Orange.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Players: Friendly]", Color.DarkGreen.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Players: Dead]", Color.Gray.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Player]", Color.White.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Target]", Color.Blue.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Party]", Color.DarkGreen.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Guild]", Color.DarkGreen.ToArgb()));
            this.arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Find]", Color.DarkGreen.ToArgb()));
            this.UpdateHashtable();
        }

        public void UpdateHashtable()
        {
            this.DisplayItems.Clear();
            foreach (clsDisplayItem item in this.arrDisplayItems)
            {
                try
                {
                    if (item.Name.StartsWith("[") && item.Name.EndsWith("]"))
                    {
                        this.DisplayItems.Add(item.Name, item);
                    }
                    else
                    {
                        this.DisplayItems.Add(item.Name.ToLower(), item);
                    }
                }
                catch
                {
                }
            }
        }
    }
}

